

import 'package:basic_common/common_exports.dart';
import 'package:basic_common/str_utils.dart';
import 'package:basic_patient/model/patient_data_list.dart';

class PatientSearchController extends GetxController {
  TextEditingController searchController = TextEditingController();
  List<PatientData>? patientList = <PatientData>[].obs;
final total=0.obs;
  /// 搜索
  /// 获取患者信息
  void searchPatientList() async {
    patientList = [];
    String search = searchController.text;
    Map<String, String> searchparame = {};
    if (StringUtil.isChinese(search)) {
      searchparame = {'name': search, "phone": "", "tag": ""};
    }
    if (StringUtil.isOnly(search)) {
      searchparame = {'name': "", "phone": search, "tag": ""};
    }
    HttpData res = await ApiService().getPatientList(data: {
      "scene": '1',
      "searchKeys": searchparame,
      "sceneDesc": "搜索",
      'pageOff': 1
    }, isShowLoading: true, loadingTitle: "正在搜索");
    if (res.code == 1) {
      if (res.data == null) {
        return;
      }
      PatientDataList patientDataList = PatientDataList.fromJson(res.data);
      total.value=patientDataList.total!;
      if (patientDataList.total! > 0) {
        patientList = patientDataList.list;
      }
    }
    update(['searchList']);
  }

  /// 签约状态值
  String signStatusTostr(String status) {
    String status = '未签约';
    switch (status) {
      case '1':
        status = '签约审核通过';
        break;
      case '2':
        status = '服务进行中';
        break;
      case '3':
        status = '服务完成';
        break;
      case '4':
        status = '签约审核拒绝';
        break;
      case '5':
        status = '已解约';
        break;
    }
    return status;
  }
}
